
<?php
use \Workerman\Autoloader;

require_once __DIR__ . '/../../../../../Workerman/Autoloader.php';
require_once __DIR__.'/../../../Config/Const.php';
Autoloader::setRootPath(__DIR__.'/../../..');

$page_groupId = GROUP_ADMIN_MNG;
$page_pageId = '个人信息';

require "../framepages/moudle_base.php";


$id = $_SESSION['USER'];

$res_admin_user = \Data\Res_admin_user_DAO::getRecord($id);
$phone_number = $res_admin_user->getPHONE_NUMBER();
$admin_name = $res_admin_user->getNAME();
$admin_password = $res_admin_user->getPASSWORD();
$admin_page = explode(',',$res_admin_user->getPAGE());

$mode = $_POST['mode'];
$result = "normal";
if($mode == 'adminEdit'){
    $phone_number = $_POST['phone_number'];
    if(!$phone_number){
        $result = "err_noId";
    } elseif (!preg_match("/^1[34578]\d{9}$/", $phone_number)) {
        $result = "err_illegalPhone";
    } else {
        $admin_name = $_POST['admin_name'];
        $admin_password = $_POST['admin_password'];
        $admin_user_page = $_POST['super_user_page'];

        $res_admin_user->setPHONE_NUMBER("$phone_number");
        $res_admin_user->setNAME("$admin_name");
        $res_admin_user->setPASSWORD("$admin_password");
        $res_admin_user->setPAGE(implode(",",$admin_user_page));
        \Data\Res_admin_user_DAO::update($res_admin_user);

        $result = "succ_update";
    }
}

?>
<div class="main-content">
    <div class="row">
        <form id="tab" method="post" action="" onSubmit="javascript:return window.confirm('确认提交吗？')">
            <div class="col-md-4">
                <input type="hidden" name="mode" id="mode" value='adminEdit'>

                <div class="panel panel-default">
                    <p class="panel-heading">操作提示：</p>
                    <div class="panel-body">
                        1：<span style="color:red;">&nbsp;*&nbsp;</span>的条目是给予管理员的权限，请认真填写<br><br>
                    </div>
                </div>

                <div class="form-group">
                    <label for="admin_name">姓名：</label>
                    <input type="text" class="form-control span12" name="admin_name" id="admin_name" value="<?php echo $admin_name ?>">
                </div>

                <div class="form-group">
                    <label for="phone_number">手机号：</label>
                    <input type="text" class="form-control span12" name="phone_number" id="phone_number" value="<?php echo $phone_number ?>">

                </div>

                <div class="form-group">
                    <label for="admin_password">密码：</label>
                    <input type="text" class="form-control span12" name="admin_password" id="admin_password" value="<?php echo $admin_password ?>"">
                </div>

                <div class="btn-toolbar list-toolbar">
                    <input type="submit" class="btn btn-danger" value="修改">
                </div>
            </div>
        </form>
    </div>

    <?php
    require "../framepages/footer.php";
    ?>
</div>
<script src="../lib/bootstrap/js/bootstrap.js"></script>

<script type="text/javascript">
    function init(){
        var msg = "<?php echo $result;?>";
        if (msg == "succ_update") {
            alert("编辑管理员成功！");
        } else if (msg == "err_noPhone") {
            alert("管理员手机号不能为空！");
        } else if (msg == "err_illegalPhone") {
            alert("手机号不合法！");
        }
    }
</script>
</body>
</html>
